pub mod term_deal;

use std::error::Error;
use std::fs::File;
use std::io::Read;


#[derive(Debug)]
pub struct IccParam {
    pub ip: String,
    pub ue_port: u32,
    pub up_port: u32,
}

impl IccParam {
    pub fn parse_and_build(file_path: &str) -> Result<IccParam, Box<dyn Error>> {
        let mut file = File::open(file_path)?;
        let mut contents = String::new();
        file.read_to_string(&mut contents)?;

        let json_value: serde_json::Value = serde_json::from_str(&contents)?;

        // 手动解析 JSON 字段
        let ip = json_value["icc_ip"]
                            .as_str()
                            .ok_or("IP not found or invalid")?
                            .to_string();
        let ue_port = json_value["icc_ue_port"]
                            .as_u64()
                            .ok_or("UE port not found or invalid")? as u32;
        let up_port = json_value["icc_up_port"]
                            .as_u64()
                            .ok_or("UP port not found or invalid")? as u32;

        Ok(IccParam { 
            ip, 
            ue_port, 
            up_port 
        })
    }
}

